package edu.caltech.cs.cs141.CopilotWeb.server;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Embedded;
import javax.persistence.Id;

import com.googlecode.objectify.annotation.Unindexed;

import edu.caltech.cs.cs141.CopilotWeb.shared.AbPoint;
import edu.caltech.cs.cs141.CopilotWeb.shared.ClientTripHeader;
import edu.caltech.cs.cs141.CopilotWeb.shared.Coordinate;
import edu.caltech.cs.cs141.CopilotWeb.shared.TripDataClient;


public class TripData {

	@Id long trip_id;
	String username;
	String triptype;
	int duration;
	int score;
	long triptime;
	
	@Unindexed
	@Embedded
	List<Coordinate> dataGPS;
	@Unindexed
	@Embedded
	List<AbPoint> dataAcc;
	
	public TripDataClient toClient() {
		TripDataClient clientdata = new TripDataClient();
		clientdata.setData(username, trip_id, score, triptype, duration, triptime, dataGPS, dataAcc);
		return clientdata;
	}
	
	public ClientTripHeader toClientHeader() {
		ClientTripHeader clientheader = new ClientTripHeader();
		int len = dataGPS.size();
		Coordinate start = dataGPS.get(0);
		Coordinate end = dataGPS.get(len - 1);
		double startlat = start.getLat();
		double endlat = end.getLat();
		double startlon = start.getLon();
		double endlon = end.getLon();
		clientheader.setData(username, trip_id, score, triptype, duration, triptime, startlon, startlat, endlon, endlat );
		return clientheader;
	}
	
	public TripData() {};
	
	public TripData(String name) {
		this.dataGPS = new ArrayList<Coordinate>();
		this.dataAcc = new ArrayList<AbPoint>();
		this.username = name;
	}
	
	public void addGData(Coordinate p) {
		dataGPS.add(p);
	}
	
	public void addAData(AbPoint p) {
		dataAcc.add(p);
	}
	

	public String getUsername() {
		return username;
	}

	public void setID(long time) {
		trip_id = time;	
	}
	
	public void setType(String type) {
		triptype = type;
	}
	
	public void setDuration(int _duration) {
		duration = _duration;
	}
	public void setScore(int _score) {
		score = _score;
	}
	
	public void setTriptime(long time) {
		triptime = time;
	}
}

